"""
员工接口对象层
"""
import requests

class IhrmEmpApi(object):
    @classmethod
    def add_emp(cls, header,  json_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user"
        resp = requests.post(url = url, headers = header, json=json_data)
        return resp

    @classmethod
    def query_emp(cls, emp_id, header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.get(url=url, headers = header)
        return resp

    @classmethod
    def modify_emp(cls, emp_id, header, json_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.put(url = url, headers = header, json = json_data)
        return resp

    @classmethod
    def del_emp(cls, emp_id, header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.delete(url = url, headers=header)
        return resp

if __name__ == '__main__':
    header = {"Content-Type":"application/json",
                   "Authorization":"Bearer 352cbf70-05ee-450b-b98d-b20ab05a6e1d"}
    data =  {"username": "猪八戒", "mobile": "17289432006", "workNumber": "9527" }
    resp = IhrmEmpApi.add_emp(header, data)
    print("添加：", resp.json())

    emp_id = "1558447351075450880"
    resp = IhrmEmpApi.query_emp(emp_id,header)
    print("查询：",resp.json())

    json_data = {"username":"齐天大圣"}
    resp = IhrmEmpApi.modify_emp(emp_id,header,json_data)
    print("修改：", resp.json())

    resp = IhrmEmpApi.del_emp(emp_id, header)
    print("删除", resp.json())




